package com.technology.education.dslitem.module

import android.content.res.ColorStateList
import android.widget.ImageView
import androidx.core.os.bundleOf
import com.angcyo.dsladapter.DslAdapterItem
import com.angcyo.dsladapter.DslViewHolder
import com.angcyo.dsladapter.dpi
import com.technology.education.R
import com.technology.education.data.model.TeachOrderModel
import com.technology.education.ext.getColor
import com.technology.education.ext.header
import com.technology.education.ext.loadImage
import com.technology.education.ext.navigation

/**
 *@author:create by BZY
 *Date: 2022/2/25 09
 */
class ItemTeacherHomeOrder : DslAdapterItem() {
    init {
        itemLayoutId = R.layout.item_teacher_home_order
    }

    override fun onItemBind(
        itemHolder: DslViewHolder,
        itemPosition: Int,
        adapterItem: DslAdapterItem,
        payloads: List<Any>
    ) {
        super.onItemBind(itemHolder, itemPosition, adapterItem, payloads)
        itemTopInsert = 10 * dpi
        itemDecorationColor = getColor(R.color.bg_activity_gray)
        itemData?.let {
            if (it is TeachOrderModel) {
                itemTag = it.id
                itemHolder.tv(R.id.tv_name)?.text = it.student.name
                itemHolder.v<ImageView>(R.id.iv_order)?.apply {
                    loadImage(it.questionImage, this)
                }
                itemHolder.clickItem { view ->
                    navigation(view, R.id.action_order_to_order_detail, bundleOf("id" to it.id))
                }
                itemHolder.tv(R.id.tv_status)?.apply {
                    text = it.appointString
                    backgroundTintList =
                        ColorStateList.valueOf(getColor(if (it.isAppoint) R.color.red else R.color.yellow_deep))
                }
                itemHolder.tv(R.id.tv_time)?.text = "时间: ${it.placeTime}"
                itemHolder.v<ImageView>(R.id.iv_header)?.apply {
                    header(it.student.avatar, this)
                }
                itemHolder.tv(R.id.tv_order_status)?.text = it.status
                itemHolder.visible(R.id.tv_order_status, !it.visibleButton)
                itemHolder.visible(R.id.btn_grab, it.visibleButton)
                itemHolder.click(R.id.iv_order, _clickListener)
                itemHolder.click(R.id.btn_grab, _clickListener)

            }
        }

    }
}